package vg.services.log_manager;

import vg.services.log_manager.interfaces.ILog;
import vg.services.log_manager.interfaces.ILogManager;
import vg.services.log_manager.interfaces.IWindowMessage;
import vg.services.log_manager.realization.FileLog;
import vg.services.log_manager.realization.SimpleLog;
import vg.services.log_manager.realization.WindowMessage;

public class LogManager implements ILogManager {
	// Mutex
	private final Object generalMutex = new Object();
	
	// Main components
	private ILog log;
	private IWindowMessage windowMessage;
	
	public LogManager() {
		try {
			log = new FileLog();
		} catch (Exception ex) {
			log = new SimpleLog();
		}
		windowMessage = new WindowMessage();
	}
	
	@Override
	public ILog getLog() {
		synchronized (generalMutex) {
			return log;
		}
	}
	
	@Override
	public IWindowMessage getWindowMessage() {
		synchronized (generalMutex) {
			return windowMessage;
		}
	}
	
	@Override
	public boolean setLog(ILog newLog) {
		synchronized (generalMutex) {
			if (newLog != null) {
				log = newLog;
				return true;
			}
		}
		return false;
	}
	
	@Override
	public boolean setWindowMessage(IWindowMessage newWindowMessage) {
		synchronized (generalMutex) {
			if (newWindowMessage != null) {
				windowMessage = newWindowMessage;
				return true;
			}
		}
		return false;
	}
}
